//
//  ClubHomeView.swift
//  77Club
//
//  Created by Apple on 2024/8/26.
//

import UIKit
import Cosmos

//MARK: 功能区以及新游榜
class ClubNewGongNengView: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UITableViewDelegate, UITableViewDataSource {

    private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    private let topView = c_make_ex(UIView.self)
        .bgColor(.white).corner(12.0.Scale).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color("#1A1A1A").font(14.font_medium).text("新游榜TOP10").end()
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = .clear
        tableView.showsVerticalScrollIndicator = false
        tableView.bounces = false
        tableView.register(ClubHomeRankCell.self)
        tableView.contentInsetAdjustmentBehavior = .never
        tableView.separatorStyle = .none
        tableView.rowHeight = 84.0.Scale
        return tableView
    }()
    private let fullButton = UIIconButton(style: .trailing(itemSpace: 4))
    var clickCateBlock: ((_ cateType: Int) -> Void)?
    
    var sourceData: [ClubHomeGongNengModel]?{
        didSet{
            collectionView.reloadData()
        }
    }
    
    var rankArray: [ClubNewHomeGameModel]?{
        didSet{
            guard let arr = rankArray, arr.count > 0 else { return }
            
            var models = [ClubNewHomeGameModel]()
            for (index, md) in arr.enumerated() {
                var model = md
                model.sort = index
                models.append(model)
            }
            rankArray = models
            tableView.reloadData()
        }
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews{
            collectionView
            topView.subviews{
                titleLabel
                tableView
                fullButton
            }
        }
        
        
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSize(width: CGFloat.screenWidth / 4, height: 70.0.Scale)
//        layout.sectionInset = UIEdgeInsets(top: 0, left: 12.0.Scale, bottom: 0, right: 0)
        
        collectionView.collectionViewLayout = layout
        collectionView.backgroundColor = .clear
        collectionView.register(ClubHomeCateCell.self, forCellWithReuseIdentifier: ClubHomeCateCell.description())
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.delegate = self
        collectionView.dataSource = self
        
        fullButton.style { v in
            v.iconSize = CGSize(width: 12.0.Scale, height: 12.0.Scale)
            v.setImage("HomeRank_go".toImage, for: .normal)
            v.setTitle("点击查看完整榜单", for: .normal)
            v.setTitleColor("#AEB0B3".toColor, for: .normal)
            v.titleLabel?.font = 12.font_medium
            v.addTarget(self, action: #selector(clickFullButton), for: .touchUpInside)
        }
        
        collectionView.leading(0).trailing(0).top(0).height(70.0.Scale)
        topView.leading(12.0.Scale).trailing(12.0.Scale).height(335.0.Scale)
        topView.Top == collectionView.Bottom + 15.0.Scale
        titleLabel.leading(20.0.Scale).top(16.0.Scale)
        tableView.leading(0).trailing(0).top(40.0.Scale).height(252.0.Scale)
        fullButton.leading(0).trailing(0).height(32.0.Scale)
        fullButton.Top == tableView.Bottom
    }
    
    @objc private func clickFullButton(){
        NotificationCenter.default.post(name: .toAllRankListVC, object: nil)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return sourceData?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ClubHomeCateCell.description(), for: indexPath) as? ClubHomeCateCell else { return UICollectionViewCell() }
        cell.model = sourceData?[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        let type = sourceData?[indexPath.row].id ?? 0
        clickCateBlock?(type)
//        if ClubLocallyStoredData.getLoginUserID().count > 0 {
//            clickCateBlock?("")
//        }else{
//            clickCateBlock?(type)
//        }
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return rankArray?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "ClubHomeRankCell", for: indexPath) as! ClubHomeRankCell
        cell.model = rankArray?[indexPath.row]
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let infoID = rankArray?[indexPath.row].id
        let dict = ["infoID": infoID]
        NotificationCenter.default.post(name: .toGameDetailVC, object: nil, userInfo: dict as [AnyHashable : Any])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK: 小编推荐
class ClubNewRecommendGameView: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    
    private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    var dataSource: [ClubNewHomeGameModel]?{
        didSet{
            collectionView.reloadData()
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        subviews{
            collectionView
        }
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSize(width: 315.0.Scale, height: 84.0.Scale)
        
        collectionView.collectionViewLayout = layout
        collectionView.backgroundColor = .clear
        collectionView.register(ClubWuKongNormalGameCell.self, forCellWithReuseIdentifier: ClubWuKongNormalGameCell.description())
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.delegate = self
        collectionView.dataSource = self
        
        collectionView.fillContainer()
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataSource?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ClubWuKongNormalGameCell.description(), for: indexPath) as? ClubWuKongNormalGameCell else { return UICollectionViewCell() }
        cell.tuijianMd = dataSource?[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        let infoID = dataSource?[indexPath.row].id
        let dict = ["infoID": infoID]
        NotificationCenter.default.post(name: .toGameDetailVC, object: nil, userInfo: dict as [AnyHashable : Any])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK: 热门游戏
class ClubNewHotGameView: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    
    private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    var dataSource: [ClubNewHomeGameModel]?{
        didSet{
            collectionView.reloadData()
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        subviews{
            collectionView
        }
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 12.0.Scale
        layout.minimumInteritemSpacing = 0
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSize(width: 120.0.Scale, height: 180.0.Scale)
        layout.sectionInset = UIEdgeInsets(top: 0, left: 12.0.Scale, bottom: 0, right: 0)
        
        collectionView.collectionViewLayout = layout
        collectionView.backgroundColor = .clear
        collectionView.register(ClubHomeHotCell.self, forCellWithReuseIdentifier: ClubHomeHotCell.description())
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.delegate = self
        collectionView.dataSource = self
        
        collectionView.top(0).bottom(0).leading(0).trailing(0)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataSource?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ClubHomeHotCell.description(), for: indexPath) as? ClubHomeHotCell else { return UICollectionViewCell() }
        cell.model = dataSource?[indexPath.row]
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        let infoID = dataSource?[indexPath.row].id
        let dict = ["infoID": infoID]
        NotificationCenter.default.post(name: .toGameDetailVC, object: nil, userInfo: dict as [AnyHashable : Any])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK: 探索更多
class ClubNewDiscoverMoreView: UITableViewCell {
//    Home_wantPlay
    private let iconImageView = c_make_ex(UIImageView.self)
        .corner(12.0.Scale).mode(.scaleAspectFill).end()
    private let shadowView = c_make_ex(UIView.self).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .color(.white).font(15.font_semiBold).alignment(.center).end()
    private let topIamgeV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(12.0.Scale).end()
    private let subLabel = c_make_ex(UILabel.self)
        .color("#7B7D80").font(12.font_medium).end()
    private let contentLabel = c_make_ex(UILabel.self)
        .color("#FF7500").font(12.font_medium).corner(4)
        .bgColor("#FF7500".toColor.alpha(0.08)).end()
    private let scoreLabel =  c_make_ex(UILabel.self)
        .color("#FF7500").font(14.font_wide).alignment(.right).end()
    private var starView = CosmosView()
    private var wantPlayButton = UIIconButton(style: .top(itemSpace: 0))
    private let iconShadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.1)).end()
    private let bgShadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.1)).end()
    
    var model: ClubNewHomeGameModel?{
        didSet{
            
            guard let md = model else { return }
            
//            iconImageView.loadImage(url: md.icon)
            iconImageView.loadImage(url: md.icon){ image, error in
                if let error = error {
                    print("图片加载失败: \(error.localizedDescription)")
                } else if let image = image {
                    let color = image.dominantColor()
                    self.shadowView.backgroundColor = color
                    self.iconImageView.layer.borderColor = color?.cgColor
                    self.iconImageView.layer.borderWidth = 2
                    self.iconImageView.layer.masksToBounds = true
                }
            }
            topIamgeV.loadImage(url: md.image)
            titleLabel.text = md.name
            let tagStr = md.biaoqian.joined(separator: " · ")
            subLabel.text = tagStr
            scoreLabel.text = "\(md.point)"
            contentLabel.text = "  " + md.summary
            let randomInt = md.randomInt
            let textColor = ClubGlobalTool.shared.textColorStr[randomInt]
            let bgColor = ClubGlobalTool.shared.bgColorStr[randomInt]
            contentLabel.textColor = textColor.toColor
            contentLabel.backgroundColor = bgColor.toColor
//            let borderRandomInt = md.borderRandomInt
//            if randomInt == 0 {
//                let borderColor = ClubGlobalTool.shared.borderColor_One[borderRandomInt]
//                self.shadowView.backgroundColor = borderColor.toColor
//                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
//                self.iconImageView.layer.borderWidth = 2
//                self.iconImageView.layer.masksToBounds = true
//            } else if randomInt == 1 {
//                let borderColor = ClubGlobalTool.shared.borderColor_Two[borderRandomInt]
//                self.shadowView.backgroundColor = borderColor.toColor
//                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
//                self.iconImageView.layer.borderWidth = 2
//                self.iconImageView.layer.masksToBounds = true
//            } else if randomInt == 2 {
//                let borderColor = ClubGlobalTool.shared.borderColor_Three[borderRandomInt]
//                self.shadowView.backgroundColor = borderColor.toColor
//                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
//                self.iconImageView.layer.borderWidth = 2
//                self.iconImageView.layer.masksToBounds = true
//            }
            contentLabel.isHidden = !(md.summary.count > 0)
            
            starView.rating = md.point/2
        }
    }
    
    var collectModel: ClubCollectGamesModel?{
        didSet{
            
            guard let md = collectModel else { return }
            
            topIamgeV.loadImage(url: md.icon)
            titleLabel.text = md.name
            let tagStr = md.biaoqian.joined(separator: " · ")
            subLabel.text = tagStr
            scoreLabel.text = "\(md.point)"
            contentLabel.text = "  " + md.summary
            let randomInt = Int.random(in: 0...2)
            let textColor = ClubGlobalTool.shared.textColorStr[randomInt]
            let bgColor = ClubGlobalTool.shared.bgColorStr[randomInt]
            contentLabel.textColor = textColor.toColor
            contentLabel.backgroundColor = bgColor.toColor
            let borderRandomInt = Int.random(in: 0..<10)
            if randomInt == 0 {
                let borderColor = ClubGlobalTool.shared.borderColor_One[borderRandomInt]
                self.shadowView.backgroundColor = borderColor.toColor
                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
                self.iconImageView.layer.borderWidth = 2
                self.iconImageView.layer.masksToBounds = true
            } else if randomInt == 1 {
                let borderColor = ClubGlobalTool.shared.borderColor_Two[borderRandomInt]
                self.shadowView.backgroundColor = borderColor.toColor
                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
                self.iconImageView.layer.borderWidth = 2
                self.iconImageView.layer.masksToBounds = true
            } else if randomInt == 2 {
                let borderColor = ClubGlobalTool.shared.borderColor_Three[borderRandomInt]
                self.shadowView.backgroundColor = borderColor.toColor
                self.iconImageView.layer.borderColor = borderColor.toColor.cgColor
                self.iconImageView.layer.borderWidth = 2
                self.iconImageView.layer.masksToBounds = true
            }
            contentLabel.isHidden = !(md.summary.count > 0)
            iconImageView.loadImage(url: md.icon)
            starView.rating = md.point/2
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        subviews{
            iconImageView.subviews{
                iconShadowView
                shadowView
                titleLabel
            }
            topIamgeV.subviews{
                bgShadowView
            }
            subLabel
            contentLabel
            scoreLabel
            starView
            wantPlayButton
        }

        topIamgeV.layer.masksToBounds = true
        
        iconImageView.leading(12.0.Scale).top(8.0.Scale).trailing(256.0.Scale).height(132.0.Scale)
        iconShadowView.fillContainer()
        shadowView.leading(0).trailing(0).bottom(0).height(30.0.Scale)
        titleLabel.leading(8).trailing(8).bottom(6.0.Scale)
        topIamgeV.leading(127.0.Scale).trailing(12.0.Scale).top(8.0.Scale).height(132.0.Scale)
        bgShadowView.fillContainer()
        starView.leading(12.0.Scale).height(14.0.Scale)
        starView.Top == iconImageView.Bottom + 10.0.Scale
        subLabel.leading(12.0.Scale).trailing(60.0.Scale)
        subLabel.Top == starView.Bottom + 8.0.Scale
        contentLabel.leading(12.0.Scale).trailing(12.0.Scale).height(22.0.Scale)
        contentLabel.Top == subLabel.Bottom + 6.0.Scale
        scoreLabel.Leading == starView.Trailing + 6.0.Scale
        scoreLabel.CenterY == starView.CenterY
        wantPlayButton.trailing(27.0.Scale).height(40.0.Scale).width(20.0.Scale)
        wantPlayButton.Top == iconImageView.Bottom + 12.0.Scale
        
        starView.rating = 0
        starView.settings.starSize = 12.0.Scale
        starView.settings.starMargin = 5
        starView.settings.fillMode = .half
        starView.settings.emptyImage = "Common_emptyStar".toImage
        starView.settings.filledImage = "Common_fillStar".toImage
        starView.isUserInteractionEnabled = false
        
        wantPlayButton.style { v in
            v.iconSize = CGSizeMake(16.0.Scale, 16.0.Scale)
            v.setImage("Home_wantPlay".toImage, for: .normal)
            v.setTitle("想玩", for: .normal)
            v.setTitleColor("#FF7500".toColor, for: .normal)
            v.titleLabel?.font = 11.font_medium
            v.isUserInteractionEnabled = false
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK: 分区titileView
class ClubHomeTitleHeaderView: UITableViewHeaderFooterView {
         
    private let nameLabel = c_make_ex(UILabel.self)
        .color("#1A1A1A").font(16.font_semiBold).end()
    
    var titleString: String? {
        didSet{
            guard let str = titleString else { return }
            nameLabel.text = str
        }
    }
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        addSubview(nameLabel)
        
        nameLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(12.0.Scale)
            make.top.equalToSuperview().offset(12.0.Scale)
        }
    }
        
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
}


//MARK: 游戏排行榜cell
class ClubHomeRankCell: UITableViewCell {

    private let rankImageV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private let iconImageV = c_make_ex(UIImageView.self)
        .corner(12.0.Scale).mode(.scaleAspectFill).end()
    private let shadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.1)).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color(.black).font(14.font_semiBold).end()
    private let tagLabel = c_make_ex(UILabel.self)
        .bgColor("#E55C67".toColor.alpha(0.1)).font(8.font_medium)
        .corner(4.0.Scale).color("#E55C67").end()
    private let subLabel = c_make_ex(UILabel.self)
        .color("#AEB0B3").font(13.font_semiBold).end()
    private let contentLabel =  c_make_ex(UILabel.self)
        .color("#FF7500").font(13.font_medium).end()
    private let logoLabel =  c_make_ex(UILabel.self)
        .color("#FF7500").font(8.font_wide).text("乐玩TOP")
        .alignment(.right).end()
    private let scoreLabel =  c_make_ex(UILabel.self)
        .color("#FF7500").font(16.font_wide).alignment(.right).end()
    
    var model: ClubNewHomeGameModel? {
        didSet{
            guard let md = model else { return }
            
            iconImageV.loadImage(url: md.icon)
            nameLabel.text = md.name
            let tagStr = md.biaoqian.joined(separator: " · ")
            subLabel.text = tagStr
            if md.pay.count > 0 {
                tagLabel.isHidden = false
                tagLabel.text = " " + md.pay + " "
            }else{
                tagLabel.isHidden = true
            }
            contentLabel.text = md.summary
            rankImageV.image = "HomeRank_\(md.sort)".toImage
            scoreLabel.text = "\(md.point)"
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.subviews{
            rankImageV
            iconImageV.subviews{
                shadowView
            }
            nameLabel
            tagLabel
            subLabel
            contentLabel
            logoLabel
            scoreLabel
        }
        
        rankImageV.leading(20.0.Scale).size(32.0.Scale).centerVertically()
        iconImageV.leading(64.0.Scale).size(60.0.Scale).centerVertically()
        shadowView.fillContainer()
        nameLabel.leading(136.0.Scale).width(<=115.0.Scale).top(12.0.Scale)
        tagLabel.height(15.0.Scale)
        tagLabel.Leading == nameLabel.Trailing + 3.0.Scale
        tagLabel.CenterY == nameLabel.CenterY
        subLabel.leading(136.0.Scale).trailing(50.0.Scale)
        subLabel.Top == nameLabel.Bottom + 2.0.Scale
        contentLabel.leading(136.0.Scale).trailing(60.0.Scale)
        contentLabel.Top == subLabel.Bottom + 2.0.Scale
        logoLabel.trailing(12.0.Scale).top(25.0.Scale)
        scoreLabel.trailing(12.0.Scale)
        scoreLabel.Top == logoLabel.Bottom - 2
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK: 热门cell
class ClubHomeHotCell: UICollectionViewCell {

    private let bgView = c_make_ex(UIView.self)
        .corner(12.0.Scale).bgColor(.white).end()
    private let topImageV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).bgColor(.white).end()
    private let iconImageV = c_make_ex(UIImageView.self)
        .corner(12.0.Scale).mode(.scaleAspectFill).end()
    private let shadowView = c_make_ex(UIView.self)
        .gradientColors(.topToBottom([.white.alpha(0),.white])).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color(.black).font(14.font_semiBold).alignment(.center).end()
    private let scoreLabel = c_make_ex(UILabel.self)
        .color("#FF7500").font(12.font_wide).alignment(.center).end()
    private let infoLabel =  c_make_ex(UILabel.self)
        .color("#2E3033").font(12.font_semiBold).text("详情").alignment(.center)
        .border("#2E3033", width: 1.5).corner(13.0.Scale).end()
    
    var model: ClubNewHomeGameModel? {
        didSet{
            guard let md = model else { return }
            
            topImageV.loadImage(url: md.image)
            iconImageV.loadImage(url: md.icon)
            nameLabel.text = md.name
            scoreLabel.text = "\(md.point)"
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.subviews{
            bgView.subviews{
                topImageV
                shadowView
                iconImageV
                nameLabel
                scoreLabel
                infoLabel
            }
        }
        
        bgView.fillContainer()
        topImageV.leading(0).trailing(0).top(0).height(80.0.Scale)
        shadowView.leading(0).trailing(0).top(0).height(80.0.Scale)
        iconImageV.size(60.0.Scale).top(24.0.Scale).centerHorizontally()
        nameLabel.leading(5).trailing(5)
        nameLabel.Top == iconImageV.Bottom + 8.0.Scale
        scoreLabel.centerHorizontally()
        scoreLabel.Top == nameLabel.Bottom + 8.0.Scale
        infoLabel.width(60.0.Scale).height(26.0.Scale).centerHorizontally()
        infoLabel.Top == scoreLabel.Bottom + 8.0.Scale
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        shadowView.rae.gradientColors(.topToBottom([UIColor.white.alpha(0),UIColor.white]))
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK: 游戏通用cell
class ClubWuKongNormalGameCell: UICollectionViewCell {
    
    private let iconImageV = c_make_ex(UIImageView.self)
        .corner(12.0.Scale).mode(.scaleAspectFill).end()
    private let shadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.1)).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color(.black).font(14.font_semiBold).end()
    private let tagLabel = c_make_ex(UILabel.self)
        .bgColor("#E55C67".toColor.alpha(0.1)).font(8.font_medium)
        .corner(4.0.Scale).color("#E55C67").end()
    private let subLabel = c_make_ex(UILabel.self)
        .color("#AEB0B3").font(13.font_semiBold).end()
    private var starView = CosmosView()
    private let scoreLabel = c_make_ex(UILabel.self)
        .color("#FF7500").font(14.font_wide).end()
    
    var model: ClubHomeInfoDetailGameModel? {
        didSet{
            guard let md = model else { return }
            
            iconImageV.loadImage(url: md.icon)
            nameLabel.text = md.name
            subLabel.text = md.system_type_text
            starView.rating = Double(md.point/2)
            scoreLabel.text = "\(md.point)"
        }
    }
    
    var tuijianMd: ClubNewHomeGameModel? {
        didSet{
            guard let md = tuijianMd else { return }
            
            iconImageV.loadImage(url: md.icon)
            nameLabel.text = md.name
            let tagStr = md.biaoqian.joined(separator: " · ")
            subLabel.text = tagStr
            starView.rating = Double(md.point/2)
            scoreLabel.text = "\(md.point)"
            if md.pay.count > 0 {
                tagLabel.isHidden = false
                tagLabel.text = " " + md.pay + " "
            }else{
                tagLabel.isHidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.subviews{
            iconImageV.subviews{
                shadowView
            }
            nameLabel
            tagLabel
            subLabel
            starView
            scoreLabel
        }
        
        iconImageV.leading(12.0.Scale).size(60.0.Scale).centerVertically()
        shadowView.fillContainer()
        nameLabel.leading(84.0.Scale).top(15.0.Scale).width(<=140)
        tagLabel.height(15.0.Scale)
        tagLabel.Leading == nameLabel.Trailing + 3.0.Scale
        tagLabel.CenterY == nameLabel.CenterY
        subLabel.leading(84.0.Scale).trailing(20.0.Scale)
        subLabel.Top == nameLabel.Bottom + 3.0.Scale
        starView.leading(84.0.Scale).height(12.0.Scale).width(68.0.Scale)
        starView.Bottom == iconImageV.Bottom - 2.0.Scale
        scoreLabel.CenterY == starView.CenterY
        scoreLabel.Leading == starView.Trailing + 4.0.Scale
        
        starView.rating = 0
        starView.settings.starSize = 12.0.Scale
        starView.settings.starMargin = 2.0.Scale
        starView.settings.fillMode = .half
        starView.settings.emptyImage = "Common_emptyStar".toImage
        starView.settings.filledImage = "Common_fillStar".toImage
        starView.isUserInteractionEnabled = false
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

//MARK: 图文分类cell
class ClubHomeCateCell: UICollectionViewCell {
    
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .color("#47494D").font(12.font_medium).alignment(.center).end()
    
    var model: ClubHomeGongNengModel?{
        didSet{
            guard let md = model else { return }
            nameLabel.text = md.name
            iconImageView.image = md.image.toImage
        }
    }
        
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = .clear
        backgroundColor = .clear
        
        contentView.subviews{
            iconImageView
            nameLabel
        }
        
        iconImageView.top(0).centerHorizontally()
        nameLabel.leading(0).trailing(0).centerHorizontally()
        nameLabel.Top == iconImageView.Bottom + 5.0.Scale
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

